package org.ljy.testdemo.controller;


import lombok.extern.slf4j.Slf4j;
import org.ljy.testdemo.aspect.CostTime;
import org.ljy.testdemo.common.Result;
import org.ljy.testdemo.exception.ApplicationException;
import org.ljy.testdemo.model.UserInfo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/test")
@RestController
public class TestController {


    @Bean("u2")
    public UserInfo getUserInfo() {
        return new UserInfo();
    }

    @Bean("u1")
    public UserInfo getUserInfo2() {
        return new UserInfo();
    }



    @RequestMapping("/t2")
    public Integer t2() {
        return 100;
    }



    @RequestMapping("/heihei")
    public Result heihei() {
        throw new ApplicationException("");
    }


    @RequestMapping("/hello")
    public String hello() {
        int a = 10/0;
        return "hello";
    }



    @RequestMapping("haha")
    public void haha() {
        throw new ApplicationException(Result.fail("我走的是构造方法"));
    }



    //测试统一结果返回的
    @CostTime
    @RequestMapping(value = "/t1",produces = "application/json")
    public String t1() throws InterruptedException {

//        Thread.sleep(3000);
        return "t1";
    }



    @RequestMapping("/t3")
    public Boolean t3() {
        return true;
    }

    @RequestMapping("/t4")
    public UserInfo t4() {
        return new UserInfo();
    }
}
